import re
import win32clipboard


def get_clipboard_text():
    """
    获取剪贴板的内容
    :return: str
    """
    try:
        win32clipboard.OpenClipboard()
        data = win32clipboard.GetClipboardData()
        win32clipboard.CloseClipboard()
        return data
    except Exception as e:
        data = ''
        print('clipboard unknown error!!', e)
    return data


if __name__ == '__main__':
    cb_text = get_clipboard_text()
    if 'create index ' in cb_text:
        sql_list = re.findall(r'((create|drop) index [^;]+)', cb_text)
        for sql in sql_list:
            print(sql[0].replace('\r\n', '\n') + ';')
